<!DOCTYPE html>
<html  lang="zh-CN" >
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="theme-color" content="#fff" id="theme-color">
  <meta name="description" content="深山磨柴斧，一鸣震江湖">
  <link rel="icon" href="/img/ic_head.jpg">
  <title>Java过渡Kotlin05：继承和接口</title>
  
  
  <meta property="og:title" content="Java过渡Kotlin05：继承和接口">
  
  
  <meta property="og:url" content="http://example.com/2020/03/02/Java%E8%BF%87%E6%B8%A1Kotlin05%EF%BC%9A%E7%BB%A7%E6%89%BF%E5%92%8C%E6%8E%A5%E5%8F%A3/index.html">
  
  
  <meta property="og:img" content="/img/ic_head.jpg">
  
  
  <meta property="og:img" content="深山磨柴斧，一鸣震江湖">
  
  
  <meta property="og:type" content="article">
  <meta property="og:article:published_time" content="2020-03-02">
  <meta property="og:article:modified_time" content="2021-04-14">
  <meta property="og:article:author" content="Cupster">
  
  
  <meta property="og:article:tag" content="Kotlin">
  
  
  
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
    var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
      }
    };
    setDarkmode();
  </script>
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
  </script>
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
  <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
  
  
  
  
<link rel="stylesheet" href="/css/main.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">

  
  
<link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">

  
  
  
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <div class="wrapper">
    
    <nav class="navbar">
  <div class="navbar-logo">
    <span class="navbar-logo-main">
      
      <img class="navbar-logo-img" src="/img/ic_head.jpg" alt="logo">
      
      <span class="navbar-logo-dsc">不负明天</span>
    </span>
  </div>
  <div class="navbar-menu">
    
    <a href="/" class="navbar-menu-item">
    
    首页
    
    </a>
    
    <a href="/archives" class="navbar-menu-item">
    
    归档
    
    </a>
    
    <a href="/tags" class="navbar-menu-item">
    
    标签
    
    </a>
    
    <a href="/categories" class="navbar-menu-item">
    
    分类
    
    </a>
    
    <a href="/about" class="navbar-menu-item">
    
    关于
    
    </a>
    
    <a href="/links" class="navbar-menu-item">
    
    友链
    
    </a>
    
    <a class="navbar-menu-item darknavbar" id="dark"><i class="iconfont icon-weather"></i></a>
    <a class="navbar-menu-item searchnavbar" id="search"><i class="iconfont icon-search" style="font-size: 1.2rem; font-weight: 400;"></i></a>
  </div>
</nav>
    
    <div id="local-search" style="display: none;">
      <input class="navbar-menu-item" id="search-input" placeholder="请输入搜索内容...">
      <div id="search-content"></div>
    </div>
    
    <div class="section-wrap">
      <div class="container">
        <div class="columns">
          <main class="main-column">
<article class="card card-content">
  <header>
    <h1 class="post-title">
      Java过渡Kotlin05：继承和接口
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2020-03-02T11:30:01.000Z">
      <i class="iconfont icon-calendar" style="margin-right: 2px;"></i>
      <span>2020-03-02</span>
    </time>
    
    <span class="dot"></span>
    
    <a href="/categories/Kotlin/" class="post-meta-link">Kotlin</a>
    
    
    
    <span class="dot"></span>
    <span>1.3k 字</span>
    
  </div>
  
  <div class="post-meta post-show-meta" style="margin-top: -10px;">
    <div style="display: flex; align-items: center;">
      <i class="iconfont icon-biaoqian" style="margin-right: 2px; font-size: 1.15rem;"></i>
      
      
        <a href="/tags/Kotlin/" class="post-meta-link">Kotlin</a>
      
    </div>
  </div>
  
  </header>
  <div id="section" class="post-content">
    <h1 id="1-继承"><a href="#1-继承" class="headerlink" title="1. 继承"></a>1. 继承</h1><p>kotlin中所有类继承Any</p>
<p>默认提供：</p>
<pre><code>equals()

hashCode()

toString()
</code></pre>
<p>注意：Any 不是 java.lang.Object。</p>
<p>kotlin类默认不能被继承，如果一个类要被继承，可以使用open关键字进行修饰。</p>
<pre><code>open class BaseActivity(p:Int)  //定义积累
class MainActivity(String[] args ,p:Int) : BaseActivity(p)
</code></pre>
<h1 id="2-构造函数"><a href="#2-构造函数" class="headerlink" title="2.构造函数"></a>2.构造函数</h1><p>如果子类有主构造函数， 则基类必须在主构造函数中立即初始化。</p>
<pre><code>open class Person(var name : String, var age : Int)&#123;// 基类

&#125;

class Student(name : String, age : Int, var no : String, var score : Int) : Person(name, age) &#123;

&#125;

// 测试
fun main(args: Array&lt;String&gt;) &#123;
    val s =  Student(&quot;Runoob&quot;, 18, &quot;S12346&quot;, 89)
    println(&quot;学生名： $&#123;s.name&#125;&quot;)
    println(&quot;年龄： $&#123;s.age&#125;&quot;)
    println(&quot;学生号： $&#123;s.no&#125;&quot;)
    println(&quot;成绩： $&#123;s.score&#125;&quot;)
&#125;
</code></pre>
<h1 id="3-子类没有主构造函数"><a href="#3-子类没有主构造函数" class="headerlink" title="3.子类没有主构造函数"></a>3.子类没有主构造函数</h1><p>如果子类没有主构造函数，则必须在每一个二级构造函数中用 super 关键字初始化基类，或者在代理另一个构造函数。初始化基类时，可以调用基类的不同构造方法。</p>
<pre><code>class Student : Person &#123;
    constructor(ctx: Context) : super(ctx) &#123;
    &#125; 
    constructor(ctx: Context, attrs: AttributeSet) : super(ctx,attrs) &#123;
    &#125;
&#125;
</code></pre>
<p>实例</p>
<pre><code>/**用户基类**/
open class Person(name:String)&#123;
    /**次级构造函数**/
    constructor(name:String,age:Int):this(name)&#123;
        //初始化
        println(&quot;-------基类次级构造函数---------&quot;)
    &#125;
&#125;

/**子类继承 Person 类**/
class Student:Person&#123;

    /**次级构造函数**/
    constructor(name:String,age:Int,no:String,score:Int):super(name,age)&#123;
        println(&quot;-------继承类次级构造函数---------&quot;)
        println(&quot;学生名： $&#123;name&#125;&quot;)
        println(&quot;年龄： $&#123;age&#125;&quot;)
        println(&quot;学生号： $&#123;no&#125;&quot;)
        println(&quot;成绩： $&#123;score&#125;&quot;)
    &#125;
&#125;

fun main(args: Array&lt;String&gt;) &#123;
    var s =  Student(&quot;Runoob&quot;, 18, &quot;S12345&quot;, 89)
&#125;
</code></pre>
<h1 id="4-重写"><a href="#4-重写" class="headerlink" title="4.重写"></a>4.重写</h1><p>基类中，使用fun声明函数时，此函数默认为final修饰，不能被子类重写。如果允许子类重写该函数，那么就要手动添加 open 修饰它, 子类重写方法使用 override 关键词</p>
<p>实例</p>
<pre><code>/**用户基类**/
open class Person&#123;
    open fun study()&#123;       // 允许子类重写
        println(&quot;我毕业了&quot;)
    &#125;
&#125;

/**子类继承 Person 类**/
class Student : Person() &#123;

    override fun study()&#123;    // 重写方法
        println(&quot;我在读大学&quot;)
    &#125;
&#125;

fun main(args: Array&lt;String&gt;) &#123;
    val s =  Student()
    s.study();

&#125;
</code></pre>
<p><strong>接口的成员变量默认是 open 的</strong></p>
<p>如果有多个相同的方法（继承或者实现自其他类，如A、B类），则必须要重写该方法，使用super范型去选择性地调用父类的实现</p>
<pre><code>open class A &#123;
    open fun f () &#123; print(&quot;A&quot;) &#125;
    fun a() &#123; print(&quot;a&quot;) &#125;
&#125;

interface B &#123;
    fun f() &#123; print(&quot;B&quot;) &#125; //接口的成员变量默认是 open 的
    fun b() &#123; print(&quot;b&quot;) &#125;
&#125;

class C() : A() , B&#123;
    override fun f() &#123;
        super&lt;A&gt;.f()//调用 A.f()
        super&lt;B&gt;.f()//调用 B.f()
    &#125;
&#125;

fun main(args: Array&lt;String&gt;) &#123;
    val c =  C()
    c.f();

&#125;
</code></pre>
<p>不是必须调用 A() 和 B() 中该函数的实现</p>
<p>如上代码片段，注释掉 super<A>.f() 和 super<B>.f() 也不报错。</p>
<h1 id="5-属性重写"><a href="#5-属性重写" class="headerlink" title="5.属性重写"></a>5.属性重写</h1><pre><code>open class Foo &#123;
    open val x: Int get &#123; …… &#125;
&#125;

class Bar1 : Foo() &#123;
    override val x: Int = ……
&#125;
</code></pre>
<p>可以用一个var属性重写一个val属性，但是反过来不行。因为val属性本身定义了getter方法，重写为var属性会在衍生类中额外声明一个setter方法</p>
<pre><code>interface Foo &#123;
    val count: Int
&#125;

class Bar1(override val count: Int) : Foo

class Bar2 : Foo &#123;
    override var count: Int = 0
&#125;   
</code></pre>
<p>1、子类继承父类时，不能有跟父类同名的变量，除非父类中该变量为 private，或者父类中该变量为 open 并且子类用 override 关键字重写:</p>
<pre><code>open class Person(var name: String, var age: Int) &#123;    
    open var sex: String = &quot;unknow&quot;    
    init &#123;        
        println(&quot;基类初始化&quot;)    
    &#125;
&#125;
// 子类的主构造方法的 name 前边也加了 var，这是不允许的，会报&#39;name&#39; hides member of supertype and needs &#39;override&#39; modifier
class Student(var name: String, age: Int, var no: String, var score: Int) : Person(name, age) &#123;
    override var sex: String = &quot;male&quot;
&#125;
</code></pre>
<p>如上代码片段中，子类 Student 主构造方法的第一个字段 name 前边加 var 关键字会报错。</p>
<h1 id="6-接口"><a href="#6-接口" class="headerlink" title="6.接口"></a>6.接口</h1><p>Kotlin 接口与 Java 8 类似，使用 interface 关键字定义接口，</p>
<p><strong>允许方法有默认实现</strong>：</p>
<pre><code>interface MyInterface &#123;
    fun bar()    // 未实现
    fun foo() &#123;  //已实现
      // 可选的方法体
      println(&quot;foo&quot;)
    &#125;
&#125;
</code></pre>
<h1 id="7-实现接口"><a href="#7-实现接口" class="headerlink" title="7.实现接口"></a>7.实现接口</h1><pre><code>与Java一致，可以实现多个接口
</code></pre>
<p>。</p>
<pre><code>class Child : MyInterface &#123;
    override fun bar() &#123;
        // 方法体
    &#125;
&#125;
</code></pre>
<p>实例</p>
<pre><code>interface MyInterface &#123;
    fun bar()
    fun foo() &#123;
        // 可选的方法体
        println(&quot;foo&quot;)
    &#125;
&#125;
class Child : MyInterface &#123;
    override fun bar() &#123;
        // 方法体
        println(&quot;bar&quot;)
    &#125;
&#125;
fun main(args: Array&lt;String&gt;) &#123;
    val c =  Child()
    c.foo();
    c.bar();
 
&#125;
//输出结果为：
foo
bar
</code></pre>
<h1 id="8-接口中的属性"><a href="#8-接口中的属性" class="headerlink" title="8.接口中的属性"></a>8.接口中的属性</h1><p> 只能是抽象的，不允许初始化。实现接口时，必须重写属性</p>
<p> interface MyInterface{<br>    var name:String //name 属性, 抽象的<br>}</p>
<p>class MyImpl:MyInterface{<br>    override var name: String = “runoob” //重写属性<br>}</p>
<p>实例</p>
<pre><code>interface MyInterface &#123;
    var name:String //name 属性, 抽象的
    fun bar()
    fun foo() &#123;
        // 可选的方法体
        println(&quot;foo&quot;)
    &#125;
&#125;
class Child : MyInterface &#123;
    override var name: String = &quot;runoob&quot; //重写属性
    override fun bar() &#123;
        // 方法体
        println(&quot;bar&quot;)
    &#125;
&#125;
fun main(args: Array&lt;String&gt;) &#123;
    val c =  Child()
    c.foo();
    c.bar();
    println(c.name)
    //foo
    bar
    runoob
&#125;
</code></pre>

  </div>
  <div>
  
  <div class="post-note note-warning copyright" style="margin-top: 42px">
    <p><span style="font-weight: bold;">作者：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/about">Cupster</a></p>
    <p><span style="font-weight: bold;">文章链接：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/2020/03/02/Java%E8%BF%87%E6%B8%A1Kotlin05%EF%BC%9A%E7%BB%A7%E6%89%BF%E5%92%8C%E6%8E%A5%E5%8F%A3/">http://example.com/2020/03/02/Java%E8%BF%87%E6%B8%A1Kotlin05%EF%BC%9A%E7%BB%A7%E6%89%BF%E5%92%8C%E6%8E%A5%E5%8F%A3/</a></p>
    <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
  </div>
  
  </div>
</article>
<div class="nav">
  
  <div class="nav-item-prev">
    <a href="/2020/03/02/Java过渡Kotlin06：扩展/" class="nav-link">
      <i class="iconfont icon-left nav-prev-icon"></i>
      <div>
        <div class="nav-label">上一篇</div>
        
        <div class="nav-title">Java过渡Kotlin06：扩展 </div>
        
      </div>
    </a>
  </div>
  
  
  <div class="nav-item-next">
    <a href="/2020/03/02/Java过渡Kotlin04：类和对象/" class="nav-link">
      <div>
        <div class="nav-label">下一篇</div>
        
        <div class="nav-title">Java过渡Kotlin04：类和对象 </div>
        
      </div>
      <i class="iconfont icon-right nav-next-icon"></i>
    </a>
  </div>
  
</div>

<div class="card card-content toc-card" id="mobiletoc">
  <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E7%BB%A7%E6%89%BF"><span class="toc-text">1. 继承</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">2.构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E5%AD%90%E7%B1%BB%E6%B2%A1%E6%9C%89%E4%B8%BB%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">3.子类没有主构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E9%87%8D%E5%86%99"><span class="toc-text">4.重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E5%B1%9E%E6%80%A7%E9%87%8D%E5%86%99"><span class="toc-text">5.属性重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-%E6%8E%A5%E5%8F%A3"><span class="toc-text">6.接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3"><span class="toc-text">7.实现接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-%E6%8E%A5%E5%8F%A3%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-text">8.接口中的属性</span></a></li></ol>
</div></main>
          <aside class="left-column">
            
            <div class="card card-author">
              
<img src="/img/ic_head.jpg" class="author-img">

<p class="author-name">Cupster</p>
<p class="author-description">深山磨柴斧，一鸣震江湖</p>
<div class="author-message">
  <a class="author-posts-count" href="/archives">
    <span>66</span>
    <span>文章</span>
  </a>
  <a class="author-categories-count" href="/categories">
    <span>5</span>
    <span>分类</span>
  </a>
  <a class="author-tags-count" href="/tags">
    <span>31</span>
    <span>标签</span>
  </a>
</div>

<div class="author-card-society">
  
    <div class="author-card-society-icon">
      <a target="_blank" rel="noopener" href="https://cupster.blog.csdn.net/">
        <i class="iconfont /img/ic_csdn.png society-icon"></i>
      </a>
    </div>
  
</div>

            </div>
            
            <div class="sticky-tablet">
  
  
  <article class="display-when-two-columns spacer">
    <div class="card card-content toc-card">
      <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E7%BB%A7%E6%89%BF"><span class="toc-text">1. 继承</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">2.构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E5%AD%90%E7%B1%BB%E6%B2%A1%E6%9C%89%E4%B8%BB%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">3.子类没有主构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E9%87%8D%E5%86%99"><span class="toc-text">4.重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E5%B1%9E%E6%80%A7%E9%87%8D%E5%86%99"><span class="toc-text">5.属性重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-%E6%8E%A5%E5%8F%A3"><span class="toc-text">6.接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3"><span class="toc-text">7.实现接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-%E6%8E%A5%E5%8F%A3%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-text">8.接口中的属性</span></a></li></ol>
    </div>
  </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header"><i class="iconfont icon-fenlei" style="padding-right: 2px;"></i>分类</div>
  <div class="categories-list">
    
      <a href="/categories/Android/">
        <div class="categories-list-item">
          Android
          <span class="categories-list-item-badge">38</span>
        </div>
      </a>
    
      <a href="/categories/Linux/">
        <div class="categories-list-item">
          Linux
          <span class="categories-list-item-badge">6</span>
        </div>
      </a>
    
      <a href="/categories/Dev-Base/">
        <div class="categories-list-item">
          Dev-Base
          <span class="categories-list-item-badge">12</span>
        </div>
      </a>
    
      <a href="/categories/Kotlin/">
        <div class="categories-list-item">
          Kotlin
          <span class="categories-list-item-badge">9</span>
        </div>
      </a>
    
      <a href="/categories/自动化脚本/">
        <div class="categories-list-item">
          自动化脚本
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header"><i class="iconfont icon-biaoqian" style="padding-right: 2px;"></i>热门标签</div>
  <div class="tags-list">
    
    <a href="/tags/Android/" title="Android"><div class="tags-list-item">Android</div></a>
    
    <a href="/tags/Android自定义View/" title="Android自定义View"><div class="tags-list-item">Android自定义View</div></a>
    
    <a href="/tags/MacOS/" title="MacOS"><div class="tags-list-item">MacOS</div></a>
    
    <a href="/tags/Kotlin/" title="Kotlin"><div class="tags-list-item">Kotlin</div></a>
    
    <a href="/tags/Android持久化/" title="Android持久化"><div class="tags-list-item">Android持久化</div></a>
    
    <a href="/tags/CentOS/" title="CentOS"><div class="tags-list-item">CentOS</div></a>
    
    <a href="/tags/Linux/" title="Linux"><div class="tags-list-item">Linux</div></a>
    
    <a href="/tags/Android事件/" title="Android事件"><div class="tags-list-item">Android事件</div></a>
    
    <a href="/tags/Android基础/" title="Android基础"><div class="tags-list-item">Android基础</div></a>
    
    <a href="/tags/Android手势/" title="Android手势"><div class="tags-list-item">Android手势</div></a>
    
    <a href="/tags/Scrcpy/" title="Scrcpy"><div class="tags-list-item">Scrcpy</div></a>
    
    <a href="/tags/Android动画/" title="Android动画"><div class="tags-list-item">Android动画</div></a>
    
    <a href="/tags/Git/" title="Git"><div class="tags-list-item">Git</div></a>
    
    <a href="/tags/Java/" title="Java"><div class="tags-list-item">Java</div></a>
    
    <a href="/tags/Docker/" title="Docker"><div class="tags-list-item">Docker</div></a>
    
    <a href="/tags/Android-Dialog/" title="Android Dialog"><div class="tags-list-item">Android Dialog</div></a>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
          <aside class="right-column">
            <div class="sticky-widescreen">
  
  
  <article class="card card-content toc-card">
    <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E7%BB%A7%E6%89%BF"><span class="toc-text">1. 继承</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">2.构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E5%AD%90%E7%B1%BB%E6%B2%A1%E6%9C%89%E4%B8%BB%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-text">3.子类没有主构造函数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E9%87%8D%E5%86%99"><span class="toc-text">4.重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E5%B1%9E%E6%80%A7%E9%87%8D%E5%86%99"><span class="toc-text">5.属性重写</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-%E6%8E%A5%E5%8F%A3"><span class="toc-text">6.接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3"><span class="toc-text">7.实现接口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-%E6%8E%A5%E5%8F%A3%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-text">8.接口中的属性</span></a></li></ol>
  </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header"><i class="iconfont icon-wenzhang_huaban" style="padding-right: 2px;"></i>最近文章</div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-03-02</div>
        <a href="/2021/03/02/Git commit规范/"><div class="recent-posts-item-content">Git commit规范</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-02-16</div>
        <a href="/2021/02/16/AutoJS一文精通AutoJS脚本教程详解/"><div class="recent-posts-item-content">AutoJS一文精通AutoJS脚本教程详解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-21</div>
        <a href="/2021/01/21/架构师进阶：注解Annotation全解/"><div class="recent-posts-item-content">架构师进阶：注解Annotation全解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-06</div>
        <a href="/2021/01/06/ConstraintLayout详解/"><div class="recent-posts-item-content">ConstraintLayout详解</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
        </div>
      </div>
    </div>
  </div>
  
  <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>Copyright ©
          
          2020 -
          
          2021
        </span>
        &nbsp;
        <a href="/" class="footer-link">不负明天 </a>
      </div>
    </div>

    
    <div class="footer-dsc">
      
      Powered by
      <a href="https://hexo.io/" class="footer-link" target="_blank" rel="nofollow noopener noreferrer">&nbsp;Hexo </a>
      
      
      <span>&nbsp;|&nbsp;</span>
      
      
      Theme -
      <a href="https://github.com/theme-kaze" class="footer-link" target="_blank"
        rel="nofollow noopener noreferrer">&nbsp;Kaze</a>
      
    </div>
    
    
    
    
      <div class="footer-dsc">
        
        本站总访问量686<span id="busuanzi_value_site_pv"></span>次
        
        
        <span>&nbsp;|&nbsp;</span>
        
        
        本站总访客数219<span id="busuanzi_value_site_uv"></span>次
        
      </div>
      
    
</footer>
  <a role="button" id="scrollbutton" class="basebutton"  aria-label="回到顶部">
  <i class="iconfont icon-arrowleft button-icon"></i>
</a>
<a role="button" id="menubutton" class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a role="button" id="popbutton" class="basebutton" aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a role="button" id="darkbutton" class="basebutton darkwidget" aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a role="button" id="searchbutton" class="basebutton searchwidget" aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a>

  
  
  
  <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img');
    var i;
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a');
      wrapper.setAttribute('href', img[i].getAttribute('data-src'));
      wrapper.setAttribute('aria-label', 'illustration');
      wrapper.style.cssText = 'width: 100%; display: flex; justify-content: center;';
      if (img[i].alt) wrapper.dataset.caption = img[i].alt;
      wrapper.dataset.nolink = true;
      img[i].before(wrapper);
      wrapper.append(img[i]);
      var divWrap = document.createElement('div');
      divWrap.classList.add('gallery');
      wrapper.before(divWrap);
      divWrap.append(wrapper);
    }
    baguetteBox.run('.gallery');
  }
</script>
<script>loadScript("/js/lib/lightbox/baguetteBox.min.js", addImgLayout)</script>
  
  
  
<script src="/js/main.js"></script>

  
  <script>loadScript("/js/lib/busuanzi.min.js")</script>
  
  
  <script>
    var addLazyload = function () {
      var observer = lozad('.lozad', {
        load: function (el) {
          el.srcset = el.getAttribute('data-src');
        },
        loaded: function (el) {
          el.classList.add('loaded');
        }
      });
      observer.observe();
    }
  </script>
  <script>loadScript("/js/lib/lozad.min.js", addLazyload)</script>
  
  
</body>

</html>